package com.example.tellwin.question.presenter;

import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.home.bean.ContentBean;
import com.example.tellwin.mine.contract.OrderDetailContract;
import com.example.tellwin.question.contract.AnswerContract;
import com.example.tellwin.utils.HttpUtils;
import com.example.tellwin.utils.ToastUtil;

import javax.inject.Inject;

import okhttp3.RequestBody;

/**
 * @author : LinZePeng
 * @date : 2020/12/7
 * @Describe ：
 **/
public class AnswerPresenter extends RxPresenter<AnswerContract.View> implements AnswerContract.Presenter<AnswerContract.View> {

    private TwjfApi mApi;

    @Inject
    public AnswerPresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }

    @Override
    public void selectAnswerType(String orderId, int type) {
        RequestBody requestBody = HttpUtils.getRequestBody("orderId", orderId, "answerType", type + "");
        mApi.selectAnswerType(requestBody, new SimpleCallback<Object>(mView) {
            @Override
            public void onSuccess(Object o) {
                mView.selectAnswerTypeResult(type);
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void userHeadPic(String userId) {
        mApi.userHeadPic(userId, new SimpleCallback<ContentBean>(mView) {
            @Override
            public void onSuccess(ContentBean contentBean) {
                mView.userHeadPic(contentBean.getUserHeadPic() ,contentBean.getRealName());
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void answerSuccess(String orderId, String answerText, String answerDuration) {
        RequestBody requestBody = HttpUtils.getRequestBody("orderId" , orderId , "answerText" , answerText , "answerDuration" ,answerDuration);
        mApi.answerSuccess(requestBody, new SimpleCallback<Object>(mView) {
            @Override
            public void onSuccess(Object obj) {
                mView.answerSuccess();
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void cancelOrder(String orderId) {
        RequestBody requestBody = HttpUtils.getRequestBody("orderId", orderId);
        mApi.cancelTakeOrder(requestBody, new SimpleCallback<Object>(mView) {
            @Override
            public void onSuccess(Object o) {
                mView.cancelOrderSuccess();
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }
}
